#!/usr/bin/python3
import RPi.GPIO as RG


def input_content(pin):
    print(RG.input(pin))


class TiltSensor:

    def __init__(self, pin: int):
        self.pin = pin
        self.title = "===================="

    def init(self):
        RG.setmode(RG.BCM)
        RG.setup(self.pin, RG.IN, pull_up_down=RG.PUD_UP)
        RG.add_event_detect(self.pin, RG.BOTH, callback=input_content, bouncetime=200)

    def loop(self):
        stop = "yes"
        while stop == "yes":
            print(self.title)
            stop = input("是否继续")
        RG.cleanup()


if __name__ == "__main__":
    input_pin = int(input("输入接收数据的GPIO接口值: "))
    m_led = TiltSensor(input_pin)
    try:
        m_led.init()
        m_led.loop()
    except KeyboardInterrupt:
        RG.cleanup()
        print("中断完成")
